// Fill out your copyright notice in the Description page of Project Settings.


#include "MyUserStateWidget.h"
#include "Components/TextBlock.h"
#include "Components/ProgressBar.h"

void UMyUserStateWidget::NativeConstruct()
{
	Super::NativeConstruct();

	// First Time Contruct the Widget
	// Set Health Progress Bar is 100%
	// Set Bullet Progress Bar is 0%
	if (ProgressBar_Health)
	{
		ProgressBar_Health->SetPercent(1.0f);
	}
	if (ProgressBar_Bullets)
	{
		ProgressBar_Bullets->SetPercent(0.0f);
	}
}

void UMyUserStateWidget::UpdateHealth(float CurrentHealth, float MaxHealth)
{
	auto ratio = CurrentHealth / MaxHealth;
	if (ProgressBar_Health)
	{
		ProgressBar_Health->SetPercent(ratio);
	}
}

void UMyUserStateWidget::UpdateBullets(int32 CurrentBullets, int32 MaxBullets)
{
	if (MaxBullets > 0)
	{
		float ratio = static_cast<float>(CurrentBullets) / static_cast<float>(MaxBullets);
		if (ProgressBar_Bullets)
		{
			ProgressBar_Bullets->SetPercent(ratio);
		}
	}
}

void UMyUserStateWidget::SetBullet_Visibility(bool isVisible)
{
	if (Bullets)
	{
		Bullets->SetVisibility(isVisible ? ESlateVisibility::Visible : ESlateVisibility::Collapsed);
	}
	if (ProgressBar_Bullets)
	{
		ProgressBar_Bullets->SetVisibility(isVisible ? ESlateVisibility::Visible : ESlateVisibility::Collapsed);
	}
}


